/**
 * 功能描述:
 * 相关配置文件:
 * @author Administrator
 */
package cn.framework.util;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

public class HttpClientUtils {

	public static List<String> getMethod(String url) throws Exception{
		List<String> resultList=new ArrayList<String>();
		HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet(url); 
        HttpResponse response;
		try {
			response = httpclient.execute(httpget);
			HttpEntity entity = response.getEntity();
			if (entity != null) {
				BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(entity.getContent()));
				String readLine=bufferedReader.readLine();
	            while(readLine!=null){
	            	resultList.add(readLine);
	            	readLine=bufferedReader.readLine();
	            }
			}
		} catch (Exception e) {
			throw e;
		}finally{
			httpget.abort();
		}
		return resultList;	     
	}
	
	public static void main(String[] args) {
		List<String> results=new ArrayList<String>();
		try {
			results = HttpClientUtils.getMethod("http://hq.sinajs.cn/list=sh600001,sh600000");
		} catch (Exception e) {
			e.printStackTrace();
		}
		for (String result : results) {
			System.out.println(result);
		}
	}
}
